package com.wgly.question.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wgly.question.bean.Msg;
import com.wgly.question.bean.Topic;
import com.wgly.question.service.TopicService;
import com.wgly.question.utils.PageBeanUtil;

import io.swagger.annotations.ApiOperation;
@Controller
public class TopicController {
	private static TopicService topicService;
    @Autowired
	public void setTopicService(TopicService topicService) {
		TopicController.topicService = topicService;
	}
    @RequestMapping("/topics")
    @ResponseBody
    @ApiOperation(value = "查询题库信息",notes="查询题库信息",httpMethod="GET",response=Topic.class)
    public Msg getTopicsWithJson(@RequestParam(value="pn",defaultValue="1")Integer pn) {
    	PageHelper.startPage(pn,5);
    	List<Topic> topic=topicService.getAll();
    	PageInfo page = new PageInfo(topic, 5);
    	PageBeanUtil pagebean=new PageBeanUtil();
    	pagebean.setPageSize(page.getPageSize());
    	pagebean.setPageNum(page.getPageNum());
    	pagebean.setTotal(page.getTotal());
    	pagebean.setTopics(page.getList());
		return Msg.success().add(pagebean);
    }
}
